package com.doit.demo_test_Class;

import javax.naming.Name;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;

@SuppressWarnings("all")
public class test {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //获取配置文件
        InputStream in = test.class.getClassLoader().getResourceAsStream("person.properties");
        Properties p = new Properties();
        p.load(in);
        in.close();

        StringBuilder sb = new StringBuilder();
        //获取类包
        String className = p.getProperty("className");
        //获取字节码文件
        Class c = Class.forName(className);
        Method[] methods = c.getDeclaredMethods();

//        创建对象
        Object obj = c.newInstance();

        //获取p中的键值对信息
        Set<String> keys = p.stringPropertyNames();
        for (String key : keys) {
            if (!key.equals("className")){

                String methodName = "set"+key.substring(0,1 ).toUpperCase()+key.substring(1);
//                System.out.println(methodName);
                //获取方法
                Method method = c.getMethod(methodName,String.class);
                //运行方法
                method.invoke(obj,p.getProperty(key));
            }
        }
        //打印对象信息
        System.out.println(obj);
    }
}
